package edu.nf.redis_retry.service;

import edu.nf.redis_retry.config.RabbitConfig;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ProduceService {

    private final RabbitTemplate rabbitTemplate;

    /**
     * 发送消息到普通队列
     * 示例：POST /send?msg=hello
     */
    @PostMapping("/send")
    public String send(@RequestParam String msg) {
        rabbitTemplate.convertAndSend(
                RabbitConfig.EXCHANGE_NAME,
                RabbitConfig.ROUTING_KEY,
                msg
        );
        return "消息已发送: " + msg;
    }
}